package com.it.emall.mapper;

import com.it.emall.domain.NutritionInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 营养信息Mapper
 */
@Mapper
public interface NutritionMapper {

    // 查询用户填写的营养信息
    @Select("SELECT * FROM nutrition_info WHERE user_id = #{userId}")
    NutritionInfo findNutritionInfoByUserId(int userId);

    // 根据用户营养需求查找合适的食谱
    @Select("SELECT id FROM recipes WHERE calories <= #{calories} AND protein >= #{protein} AND Fat <= #{Fat} AND carbohydrate <= #{carbohydrate}")
    List<Integer> findRecipesByNutrition(int calories, int protein, int Fat, int carbohydrate);

    /**
     * 插入用户营养信息
     */
    @Insert("INSERT INTO nutrition_info (user_id, calories, protein, fat, carbohydrate) " +
            "VALUES (#{userId}, #{calories}, #{protein}, #{fat}, #{carbohydrate})")
    void insertNutritionInfo(NutritionInfo nutritionInfo);
}
